/*	PureMVC AS3 / Flex Demo - Slacker 
	Copyright (c) 2008 Clifford Hall <clifford.hall@puremvc.org>
	Your reuse is governed by the Creative Commons Attribution 3.0 License */
package mvc.view
{
	import com.tools.traceTool.TraceTool;
	
	import components.MainDisplay;
	
	import flash.events.Event;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

    public class MainDisplayMediator extends Mediator
    {
		public static const NAME:String = 'MainDisplayMediator';

		private function Trace(...args):void{TraceTool.send('bTrace', String(Object(this).constructor), args);}

		public function MainDisplayMediator(viewComponent:Object)
		{
			Trace('		START	constructor	'+viewComponent);
			super( NAME, viewComponent );
			Trace('		FINISH	constructor	'+mainDisplay);
		}
		override public function onRegister():void
		{
			Trace('	onRegister	EventListeners');
			mainDisplay.addEventListener(ArtGConfig.COLL_CREATED,	onCollectionCreated);
			mainDisplay.addEventListener(ArtGConfig.HOME_CREATED,	onHomeCreated);
		}
		protected function onCollectionCreated(event:Event):void{checkForMediator( ArtGConfig.COLL, mainDisplay.activeView);}
		protected function onHomeCreated(	event:Event):void{checkForMediator( ArtGConfig.HOME,	mainDisplay.activeView);}

		override public function listNotificationInterests():Array
		{
			Trace('	listNotificationInterests');
			return [ArtGConfig.HOME_MODE,
					ArtGConfig.ART_MODE,
					ArtGConfig.ABOUT_MODE,
					ArtGConfig.CONTACT_MODE,
					ArtGConfig.COLL_MODE,
					ArtGConfig.TMP_MODE]
		}
		override public function handleNotification(note:INotification):void
		{
			Trace('	handleNotification	'+note.getName());
			switch (note.getName())
			{
				case ArtGConfig.TMP_MODE:		mainDisplay.viewSelector=ArtGConfig.TMP;	break;
				case ArtGConfig.ART_MODE:	//	mainDisplay.currentViewSelector=ArtGConfig.ART;		break;
				case ArtGConfig.ABOUT_MODE:	//	mainDisplay.currentViewSelector=ArtGConfig.ABOUT;	break;
				case ArtGConfig.CONTACT_MODE://	mainDisplay.currentViewSelector=ArtGConfig.CONTACT;	break;
				case ArtGConfig.HOME_MODE:		mainDisplay.viewSelector=ArtGConfig.HOME;	break;
				case ArtGConfig.COLL_MODE:		mainDisplay.viewSelector=ArtGConfig.COLL;	break;
				default:	Trace('ERROR	handleNotification	default');
			}
		}
		protected function checkForMediator(childSelector:Number,child:Object):void
		{
			Trace('	checkForMediator	'+childSelector+'	'+child);
			switch (childSelector)
			{
				case ArtGConfig.COLL:	if(!facade.hasMediator( CollViewMediator.NAME ))	facade.registerMediator(new CollViewMediator(child));break;
				case ArtGConfig.CONTACT://if(!facade.hasMediator( DefaultViewMediator.NAME))facade.registerMediator(new DefaultViewMediator(child));break;
				case ArtGConfig.ABOUT:	//if(!facade.hasMediator( DefaultViewMediator.NAME))facade.registerMediator(new DefaultViewMediator(child));break;
				case ArtGConfig.ART:	//if(!facade.hasMediator( DefaultViewMediator.NAME))facade.registerMediator(new DefaultViewMediator(child));break;
				case ArtGConfig.HOME:	if(!facade.hasMediator( DefaultViewMediator.NAME))facade.registerMediator(new DefaultViewMediator(child));break;
				default:	Trace('ERROR	checkForMediator	default');
			}
		}
		protected function get mainDisplay():MainDisplay{return MainDisplay(viewComponent);}
    }
}